package com.coc.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * Topic 模式
 */
@Configuration
public class RabbitTopicConfig {

    @Bean
    public Queue topicA() {
        return new Queue("topic.a");
    }

    @Bean
    public Queue topicB(){
        return new Queue("topic.b");
    }

    @Bean
    public Queue topicC(){
        return new Queue("topic.c");
    }

    /**
     * 定义个topic交换器
     * @return
     */
    @Bean
    public TopicExchange topicExchange(){
        return new TopicExchange("topic.Exchange");
    }

    /**
     *  将定义的topicA队列与topicExchange交换机绑定
     * @return
     */
    @Bean
    public Binding bindingTopicWithA(){
        return BindingBuilder.bind(topicA()).to(topicExchange()).with("topic.msg");
    }

    /**
     * 将定义的topicB队列与fanoutExchange交换机绑定
     * @return
     */
    @Bean
    public Binding bindingTopicWithB(){
        return BindingBuilder.bind(topicB()).to(topicExchange()).with("topic.#");
    }

    /**
     * 将定义的topicC队列与fanoutExchange交换机绑定
     * @return
     */
    @Bean
    public Binding bindingTopicWithC(){
        return BindingBuilder.bind(topicC()).to(topicExchange()).with("topic.*.z");
    }

}
